/*!
  @file text_handler.h
  @brief Brief Description
  @author Kyohei Otsu <kyon@ac.jaxa.jp>
  @date April, 2013
*/

#ifndef _TEXT_HANDLER_H_
#define _TEXT_HANDLER_H_

#include <errno.h>
#include <stdio.h>

#include "net/data_handler.h"
#include "core/core.h"

namespace net
{

//! Text handler
class TextHandler : public DataHandler
{
 public:

  //! Constructor
  TextHandler() : DataHandler() { CHUNK_SIZE = 8; }
  TextHandler(const int sock, const char *mode) : DataHandler(sock, mode) { }

  //! Destructor
  ~TextHandler() { }


 private:

  virtual int onReceive()
  {
    while (int num_read = fread(buf_, 1, CHUNK_SIZE, fp_)) {
      INFO(buf_);
    }
#if 0
    while (fgets((char*)buf_, CHUNK_SIZE, fp_) != NULL) {
      INFO(buf_);
    }
#endif
    return 0;
  }

  virtual int onSend()
  {
    std::string msg("hello world");
    INFO("sending " << msg);
    fwrite(msg.c_str(), 1, msg.length()+1, fp_);
    return 0;
  }

};

} // end of namespace

#endif
